﻿@model FlexFlow.Model.User

@{
    Layout = null;
}
<script src="~/Assets/js/jquery.form.js"></script>
<script src="~/assets/js/jquery.validate.min.js"></script>
<div class="row">
    <form class="form-horizontal" role="form" id="frmUserUpdate">
        <input type="text" style="visibility:hidden" value=@Model.Identity id="uid" name="uid" />
        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="name"> 姓名 </label>
            <div class="col-sm-9">
                <input type="text" id="name" name="name" placeholder="姓名" value="@Model.Name" class="col-xs-12 col-sm-9">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="name"> 账号 </label>
            <div class="col-sm-9">
                <input type="text" id="account" name="account" placeholder="账号" value="@Model.Account" class="col-xs-12 col-sm-9">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="name"> 密码 </label>
            <div class="col-sm-9">
                <label class="btn btn-xs btn-danger tooltip-warning" data-rel="tooltip" data-placement="right" data-original-title="点击过后将会把当前用户密码重置为默认密码（@FlexFlow.Runtime.UserManager.DefaultPassword）" onclick="resetPwd()">
                    <i class="icon-undo bigger-110"></i>
                    重置密码
                    <i class="icon-arrow-right icon-on-right"></i>
                </label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="name"> Email </label>
            <div class="col-sm-9">
                <input type="text" id="email" name="email" placeholder="EMail" value="@Model.Email" class="col-xs-12 col-sm-9">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="name"> 所在机构 </label>
            <div class="col-sm-9">
                <input type="text" id="orgName" name="orgName" placeholder="所在机构" readonly="readonly" value="@Model.OrganizeName" class="col-xs-12 col-sm-9">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="name"> 锁定 </label>
            <div class="col-sm-9">
                <label>
                    <input name="isLock" class="ace ace-switch ace-switch-4" type="checkbox" checked="@(Model.Locked)">
                    <span class="lbl"></span>
                </label>
            </div>
        </div>
        <div class="col-md-offset-3 col-md-9">
            <button class="btn btn-info" type="submit">
                <i class="icon-ok bigger-110"></i>
                提交
            </button>

            &nbsp; &nbsp; &nbsp;
            <button class="btn" type="reset">
                <i class="icon-undo bigger-110"></i>
                重设
            </button>
        </div>
    </form>
    <script>
        function doUpdateUser() {
            $("#frmUserUpdate").ajaxSubmit({
                type: "POST",
                url: "/userapi/update",
                success: function (response, statusText) {
                    var ref = $('#orgTree').jstree(true);
                    ref.refresh();
                    bootbox.dialog({
                        message: response.Message,
                        buttons: {
                            "success": {
                                "label": "确定",
                                "className": "btn-sm btn-primary"
                            }
                        }
                    });
                }
            })
        }

        function resetPwd() {
            bootbox.confirm("确定要重置用户" + $("#name").attr('value') + "(" + $("#account").attr('value') + ")" + "的密码么？", function (res) {
                if (res == true) {
                    doOperation({
                        'url': '/userapi/changepassword',
                        'data': {
                            'uid': $("#uid").attr('value')
                        },
                        'success': function (d) {
                            bootbox.alert("重置密码成功！");
                        }
                    })
                }
            });
        }

        $('#frmUserUpdate').validate(buildOpt(doUpdateUser, function () { }));
        $('[data-rel=tooltip]').tooltip();

    </script>
</div>
